package com.cqh.servlet;

import com.cqh.bean.Grade;
import com.cqh.bean.Student;
import com.cqh.service.GradeService;
import com.cqh.service.StudentService;
import com.cqh.service.impl.GradeServiceImpl;
import com.cqh.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/Educational/student/findById")
public class FindByIdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收参数
        String stuId = req.getParameter("stuId");
        //根据主键查询学生信息
        StudentService studentService = new StudentServiceImpl();
        Student student = studentService.findById(Integer.parseInt(stuId));

        //查询年级列表
        GradeService gradeService = new GradeServiceImpl();
        List<Grade> gradeList = gradeService.getGradeList();

        req.setAttribute("stu",student);
        req.setAttribute("gradeList",gradeList);
        req.getRequestDispatcher("edit.jsp").forward(req,resp);
    }
}
